<?php

/**
 * Description of Model_module
 *
 * @author Meta Sanjaya
 */
class Model_module extends MY_Model {
    public function __construct() {
        parent::__construct();
    }

    /**
     *
     * @param int $id
     * @return Obj_Module
     */
    function get_module($id) {
        $query = $this->db->query("select * from `".DATABASE_ERP."`.`module` where `id` = $id");

        if($query->num_rows() < 1) {
            return false;
        }

        $module = $query->row();
        $module->child = $this->get_child_modules($module->id);

        return $module;
    }

    /**
     *
     * @param int $id
     * @param array $exclude
     * @return Obj_Module
     */
    function get_child_modules($id) {
        $query = $this->db->query("select * from `".DATABASE_ERP."`.`module` where `parent` = $id");

        if($query->num_rows() < 1) {
            return array();
        }

        $modules = array();

        foreach ($query->result() as $module) {
            $module->child = $this->get_child_modules($module->id);
            $modules[] = $module;
        }

        return $modules;
    }
}
?>
